Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectSound
Imports System.Threading
Imports System.Random
Imports System.IO

Public Class Sound

    'Private data members
    Private device As Device
    Private capture As Capture
    Private buffer As Buffer
    Private bufferDesc As BufferDescription
    Private captureBuffer As CaptureBuffer
    Private waveFormat As WaveFormat
    Private captureBuffDesc As CaptureBufferDescription
    Private stream As MemoryStream
    Private streamBuffer As New Byte()

    ''' <summary>
    ''' Constructor
    ''' </summary>
    Public Sub New()

        CreateDevice()
        CreateWaveFormat()
        CreateBufferDescription()
        CreateBuffer()
        SetCooperativeLevel()
        CreateCapture()
        CreateCapureDescription()
        CreateCaptureBuffer()
        CreateStreamBuffer()
        CreateStream()

    End Sub


    Private Sub CreateDevice()

        device = New Device()

    End Sub


    Private Sub CreateBuffer()

        buffer = New Buffer(bufferDesc, Me.device)

    End Sub

    Private Sub CreateBufferDescription()

        bufferDesc = New BufferDescription()
        bufferDesc.Format = waveFormat
        bufferDesc.BufferBytes = 100000
        bufferDesc.ControlPositionNotify = True
        bufferDesc.ControlFrequency = True
        bufferDesc.ControlPan = True
        bufferDesc.ControlVolume = True
    End Sub

    Private Sub SetCooperativeLevel()

        'TODO - Pass Form Object To This Instead Of Me
        'device.SetCooperativeLevel(Me, CooperativeLevel.Priority)

    End Sub

    Private Sub CreateWaveFormat()

        waveFormat = New WaveFormat()
        waveFormat.BitsPerSample = 16
        waveFormat.BlockAlign = 1
        waveFormat.Channels = 1
        waveFormat.AverageBytesPerSecond = 44100
        waveFormat.SamplesPerSecond = 44100
        waveFormat.FormatTag = WaveFormatTag.Pcm

    End Sub

    Private Sub CreateCapture()

        capture = New Capture()

    End Sub

    Private Sub CreateCapureDescription()

        captureBuffDesc = New CaptureBufferDescription()
        captureBuffDesc.BufferBytes = 100000
        captureBuffDesc.Format = waveFormat

    End Sub

    Private Sub CreateCaptureBuffer()

        captureBuffer = New CaptureBuffer(captureBuffDesc, capture)

    End Sub

    Private Sub CreateStream()

        stream = New MemoryStream(streamBuffer)

    End Sub

    Private Sub CreateStreamBuffer()

        streamBuffer = New Byte()

        Dim counter As Integer = 0

        While counter < 100000

            'streamBuffer(counter) = 0

        End While

    End Sub

    Public Sub Record()



    End Sub


End Class
